package com.turman.demo

import android.os.Bundle
import android.util.Log
import android.widget.Toast
import com.turman.blibrary.manager.ActivityManager
import com.turman.common.ui.component.BaseActivity

class MainActivity : BaseActivity(), MainActivityLogic.ActivityProvider {
    private lateinit var mainActivityLogic: MainActivityLogic

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.act_main)

        mainActivityLogic = MainActivityLogic(this, savedInstanceState)

        ActivityManager.instance.addFrontbackCallback(object : ActivityManager.FrontBackCallback {
            override fun onChanged(front: Boolean) {                if (front) {
                Toast.makeText(this@MainActivity,"切换到前台",Toast.LENGTH_SHORT).show()
                Log.i("buobao", "切换到前台")
            } else {
                Toast.makeText(this@MainActivity,"切换到后台",Toast.LENGTH_SHORT).show()
                Log.i("buobao", "切换到后台")
            }

            }
        })
    }

    /**
     * 解决页面朝向变化时重复加载fragment
     * @author buobao
     * @since 2024/3/12 14:18
     */
    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        mainActivityLogic.onSaveInstanceState(outState)
    }
}